#!/bin/sh
# counts instructions for a standard workload
set -e

OUTFILE="cachegrind.stress2.`git describe --always --dirty`-`date +%s`"

rm -rf default.sled || true

cargo build \
  --bin=stress2 \
  --release


# --tool=callgrind --dump-instr=yes --collect-jumps=yes --simulate-cache=yes \
# --callgrind-out-file="$OUTFILE" \

valgrind \
  --tool=cachegrind \
  --cachegrind-out-file="$OUTFILE" \
  ./target/release/stress2 --total-ops=50000 --set-prop=1000000000000 --threads=1

LAST=`ls -t cachegrind.stress2.* | sed -n 2p`

echo "comparing $LAST with new $OUTFILE"

echo "--------------------------------------------------------------------------------"
echo "change since last run:"
echo "         Ir   I1mr  ILmr          Dr    D1mr    DLmr          Dw    D1mw    DLmw"
echo "--------------------------------------------------------------------------------"
cg_diff $LAST $OUTFILE | tail -1
